package com.anche.cywebnew.Service.systemManager.Impl;

import com.anche.cywebnew.DAO.systemManager.RoleResourceMapper;
import com.anche.cywebnew.Pojo.systemManager.RoleResource;
import com.anche.cywebnew.Service.systemManager.RoleResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.beans.Transient;
import java.util.List;

@Service
public class RoleResourceServiceImpl implements RoleResourceService {

    @Autowired
    private RoleResourceMapper roleResourceMapper;

    @Override
    public List<String> getRoleResourceList(String roleId) {
        return roleResourceMapper.selectLowestResource(roleId);
    }

    @Override
    @Transient
    public void setResourceIdList(String roleId, String resourceId) {
        roleResourceMapper.deleteByRoleId(roleId); //先删除以前的资源列表
        String[] resourceIdArr = resourceId.split(",");
        for (String id : resourceIdArr) {
            roleResourceMapper.insertRoleResource(new RoleResource(roleId, id)); //添加新的资源列表
        }
    }
}
